class Acces
  attr_reader :borne,:camera,:teleporteurs,:parking
  require './Modele/Borne'
  require './Modele/Camera'
  require './Modele/Teleporteur'
  require 'sqlite3'
  require 'securerandom' 
  
  def initialize(parking)
    @borne = Borne.new(self)
    @parking = parking
    @camera = Camera.new(self)
    @teleporteurs = [Teleporteur.new(parking)]*2
  end
  
  def affecter_place(vehi,client)
     tab_libre=@parking.place_libres(client)
     if tab_libre.size()>0 then
       tab_libre[0].ticket=SecureRandom.hex(3)
       tab_libre[0].vehicule=@camera.capturer_vehicule(vehi)
       @parking.db.execute("insert into Places values (#{tab_libre[0].id}, '#{vehi.immat}',#{tab_libre[0].niveau},'#{tab_libre[0].ticket}')")
       if @parking.existe_vehicule?(vehi) != true
        @parking.db.execute("insert into Vehicules values ('#{vehi.immat}',#{vehi.hauteur},#{vehi.longueur});")
       end
       return tab_libre[0]
     else
       return nil
     end 
   end
  
 
end